{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 绑定和可变性/Binding and mutability"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "vscode": {
     "languageId": "rust"
    }
   },
   "outputs": [
    {
     "ename": "Error",
     "evalue": "used binding `x` isn't initialized",
     "output_type": "error",
     "traceback": [
      "println!(\"x is equal to {}\", x); ",
      "                             ^ `x` used here but it isn't initialized",
      "let x: i32; // 未初始化，但被使用",
      "    ^ binding declared here but left uninitialized",
      "used binding `x` isn't initialized",
      "help: consider assigning a value\n\n = 42"
     ]
    },
    {
     "ename": "Error",
     "evalue": "used binding `y` isn't initialized",
     "output_type": "error",
     "traceback": [
      "let y: i32; // 未初始化，也未被使用",
      "    ^ binding declared here but left uninitialized",
      "used binding `y` isn't initialized",
      "help: consider assigning a value\n\n = 42"
     ]
    }
   ],
   "source": [
    "// 1. 🌟 变量只有在初始化后才能被使用\n",
    "\n",
    "\n",
    "// 修复下面代码的错误并尽可能少的修改\n",
    "let x: i32; // 未初始化，但被使用\n",
    "let y: i32; // 未初始化，也未被使用\n",
    "println!(\"x is equal to {}\", x); "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "vscode": {
     "languageId": "rust"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x is equal to 1\n"
     ]
    }
   ],
   "source": [
    "let x: i32 = 1;\n",
    "let y: i32 = 2;\n",
    "println!(\"x is equal to {}\", x); "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "vscode": {
     "languageId": "rust"
    }
   },
   "outputs": [],
   "source": [
    "// 2. 🌟🌟 可以使用 mut 将变量标记为可变\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Rust",
   "language": "rust",
   "name": "rust"
  },
  "language_info": {
   "codemirror_mode": "rust",
   "file_extension": ".rs",
   "mimetype": "text/rust",
   "name": "Rust",
   "pygment_lexer": "rust",
   "version": ""
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
